%% OBJECTIVE FUNCTION WITH KNOWN TYPE
function o = type_fun(z, x, v,params)
%% parameters
temp = num2cell(params);
[rho, r, ra, alpha, sigma, lambda, M, eta_min, eta_max] = temp{:};

%% Objective
C = z(:,1);
B = z(:,2);
Eta = z(:,3);

ExRet = sigma.*Eta.*x;
K = B.*C.^rho./(sigma*lambda);

o = C - ExRet.*K + ...
        v.* ( ra - C.^(1-rho)./(1-rho) + 0.5.*rho*B.^2);
    
end